//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Management.Instrumentation;

namespace EntLibContrib.Resource.Configuration.Manageability
{
	/// <summary>
	/// Represents the configuration information from a 
	/// <see cref="EntLibContrib.Resource.Configuration.CustomResourceProviderData"/> instance.
	/// </summary>
	/// <seealso cref="ResourceProviderSetting"/>
	[ManagementEntity]
	public class CustomResourceProviderSetting : ResourceProviderBaseSetting
	{
		#region Fields
		private string[] attributes;
		private string providerType;
		#endregion

		#region Properties
		/// <summary>
		/// Gets the collection of attributes for the custom resource provider represented as a
		/// <see cref="string"/> array of key/value pairs for the represented configuration object.
		/// </summary>
		/// <value>The attributes.</value>
		/// <seealso cref="EntLibContrib.Resource.Configuration.CustomResourceProviderData.Attributes">CustomResourceProviderData.Attributes</seealso>
		[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
		[ManagementProbe]
		public string[] Attributes
		{
			get { return attributes; }
			set { attributes = value; }
		}

		/// <summary>
		/// Gets the name of the type for the custom resource provider for the represented configuration object.
		/// </summary>
		/// <value>The type of the provider.</value>
		/// <seealso cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.NameTypeConfigurationElement.Type">Inherited NameTypeConfigurationElement.Type</seealso>
		[ManagementProbe]
		public string ProviderType
		{
			get { return providerType; }
			set { providerType = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="CustomResourceProviderSetting"/> class with a name, the provider type,
		/// and the attributes.
		/// </summary>
		/// <param name="name">The name of the resource provider.</param>
		/// <param name="providerType">The type of the provider.</param>
		/// <param name="attributes">The attributes for the provider.</param>
		public CustomResourceProviderSetting(string name,
																				string providerType,
																				string[] attributes)
			: base(name)
		{
			this.providerType = providerType;
			this.attributes = attributes;
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Returns an enumeration of the published <see cref="CustomResourceProviderSetting"/> instances.
		/// </summary>
		/// <returns></returns>
		[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate"), ManagementEnumerator]
		public static IEnumerable<CustomResourceProviderSetting> GetInstances()
		{
			return GetInstances<CustomResourceProviderSetting>();
		}

		/// <summary>
		/// Returns the <see cref="CustomResourceProviderSetting"/> instance corresponding to the provided values for the key properties.
		/// </summary>
		/// <param name="applicationName">Name of the application.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <param name="name">The name.</param>
		/// <returns>
		/// The published <see cref="CustomResourceProviderSetting"/> instance specified by the values for the key properties,
		/// or <see langword="null"/> if no such an instance is currently published.
		/// </returns>
		[ManagementBind]
		public static CustomResourceProviderSetting BindInstance(string applicationName,
																														 string sectionName,
																														 string name)
		{
			return BindInstance<CustomResourceProviderSetting>(applicationName, sectionName, name);
		}
		#endregion
	}
}
